//package cn.nfwx.tv.controller;
//
//import android.app.Activity;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.OrientationHelper;
//import android.support.v7.widget.RecyclerView;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.CompoundButton;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//
//import org.greenrobot.eventbus.EventBus;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import cn.nfwx.tv.R;
//import cn.nfwx.tv.adapter.DownLoadedAdapter;
//import cn.nfwx.tv.divider.RecycleViewDivider;
//import cn.nfwx.tv.events.DownLoadedDeleteEvents;
//import cn.nfwx.tv.events.EditEvents;
//import cn.nfwx.tv.manager.DownLoadManager;
//import cn.nfwx.tv.util.NetworkUtil;
//import p2psvideo.P2PSMgr;
//
///**
// * Created by dell on 2017/11/22.
// */
//
//public class DownloadedViewController implements View.OnClickListener, DownLoadedAdapter.OnCheckedChangeDeleteListener {
//    private Activity activity;
//    private RecyclerView recyclerView;
//    private DownLoadedAdapter adapter;
//    private LinearLayout bottom_layout;
//    private TextView downloaded_cancle,downloaded_delete_btn;
//    private boolean isFull=false;
//    private DownLoadedAdapter.OnItemClickListener onItemClickListener;
//    private List<P2PSMgr.P2PSFileInfo> mData=new ArrayList<P2PSMgr.P2PSFileInfo>();
//    private View notDataView;
//    private View errorView;
//    private ImageView empty_image,error_image;
//    private TextView empty_text,error_text;
//    private LinearLayout error_refresh_btn;
//
//    public DownloadedViewController(Activity activity, View view){
//        this.activity=activity;
//        initView(view);
//    }
//    public void initView(View view){
//        recyclerView=findView(view, R.id.downloaded_recyclerView);
//        bottom_layout=findView(view,R.id.bottom_layout);
//        downloaded_cancle=findView(view,R.id.downloaded_cancle);
//        downloaded_delete_btn=findView(view,R.id.downloaded_delete_btn);
//        errorView= activity.getLayoutInflater().inflate(R.layout.dialog_network_error, (ViewGroup) recyclerView.getParent(), false);
//        notDataView = activity.getLayoutInflater().inflate(R.layout.view_nodata, (ViewGroup) recyclerView.getParent(), false);
//        error_image=errorView.findViewById(R.id.error_image);
//        error_text=errorView.findViewById(R.id.error_text);
//        empty_image=notDataView.findViewById(R.id.empty_image);
//        empty_text=notDataView.findViewById(R.id.empty_text);
//        error_refresh_btn=errorView.findViewById(R.id.error_refresh_btn);
//        empty_image.setImageResource(R.mipmap.empty_download);
//        empty_text.setText("暂无下载完成视频");
//        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(activity);
//        linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
//        recyclerView.setLayoutManager(linearLayoutManager);
//        recyclerView.addItemDecoration(new RecycleViewDivider(activity,LinearLayoutManager.HORIZONTAL,R.drawable.divider_item_normal));
//        adapter=new DownLoadedAdapter(R.layout.fragment_downloaded_item, mData);
//        adapter.setOnCheckedChangeDeleteListener(this);
//        recyclerView.setAdapter(adapter);
//        downloaded_cancle.setOnClickListener(this);
//        downloaded_delete_btn.setOnClickListener(this);
//        error_refresh_btn.setOnClickListener(this);
//       setData();
//    }
//    public void setData(){
//
//            mData = DownLoadManager.getDownLoadedList(activity);
//            if (mData.size() == 0) {
//                adapter.setEmptyView(notDataView);
//            } else {
//                adapter.setNewData(mData);
//            }
//
//    }
//
//    public DownLoadedAdapter getAdapter(){
//        if(adapter==null){
//            adapter=new DownLoadedAdapter(R.layout.fragment_downloaded_item, mData);
//        }
//        return adapter;
//    }
//
//    public void setPlayClickLisenter(DownLoadedAdapter.OnItemClickListener onItemClickListener){
//        this.onItemClickListener=onItemClickListener;
//        adapter.setOnItemClickListener(this.onItemClickListener);
//    }
//
//    public void setBottomLayoutVisiable(boolean visiable){
//        bottom_layout.setVisibility(visiable?View.VISIBLE:View.GONE);
//    }
//
//    public void setCancleText(String text,boolean bold){
//        downloaded_cancle.setText(text);
//
//    }
//
//
//    /**
//     * 查找控件
//     *
//     * @param rid
//     * @param <T>
//     * @return
//     */
//    public <T extends View> T findView(View view, int rid) {
//        return (T) view.findViewById(rid);
//    }
//
//
//    @Override
//    public void onClick(View view) {
//        switch (view.getId()){
//           case  R.id.downloaded_cancle:
//                if(isFull){
//                    adapter.getDeleteData().clear();
//                    adapter.notifyDataSetChanged();
//                    isFull=false;
//                    downloaded_cancle.setText("全选");
//                }else{
//                    for(int i=0;i<adapter.getData().size();i++){
//                        if(!adapter.getDeleteData().containsKey(i)){
//                            adapter.getDeleteData().put(i,adapter.getData().get(i).vsid);
//                        }
//                    }
//                    downloaded_cancle.setText("取消全选");
//                    adapter.notifyDataSetChanged();
//                    isFull=true;
//                }
//             break;
//            case R.id.downloaded_delete_btn:
//
//                Map<Integer,String> map= adapter.getDeleteData();
//                for(Integer id:map.keySet()){
//                    DownLoadManager.deleteDownLoad(activity,map.get(id));//删除下载视频
//                    mData.remove(adapter.getItem(id));
//                }
//                mData=DownLoadManager.getDownLoadedList(activity);
//                adapter.setNewData(mData);
//                adapter.getDeleteData().clear();
//                bottom_layout.setVisibility(View.GONE);
//                adapter.notifyDataSetChanged();
//                EventBus.getDefault().post(new EditEvents());
//                break;
//            case R.id.error_refresh_btn:
//                error_image.setImageResource(R.drawable.footer_loading_progress);
//                setData();
//                break;
//        }
//    }
//
//    @Override
//    public void onCheckedChanged(CompoundButton compoundButton, boolean b, int position) {
//        if(b){
//            adapter.getDeleteData().put(position,adapter.getData().get(position).vsid);
//        }else{
//            adapter.getDeleteData().remove(adapter.getDeleteData().get(position));
//        }
//        if(adapter.getDeleteData().keySet().size()==adapter.getData().size()){
//            downloaded_cancle.setText("取消全选");//全部勾上
//            isFull=true;
//        }else{
//            downloaded_cancle.setText("全选");//还未全部勾上
//            isFull=false;
//        }
//    }
//}
